﻿##### variables #####

$s = "MFJ,AMERITRON,KENWOOD"
$s = $s.split(",")
$emailto = "craig.david@mt.com,craigdavidaus@gmail.com"
$datefile = "d:\ur-date.txt"
$url = "http://www.universal-radio.com/alert.txt"

$emailFrom = "craig.david@mt.com"
$subject = "Universal-radio - used or demo product found"
$smtpServer = "smtp.mtus.mtnet"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)


$webText = ""

#######


$wc = New-Object System.Net.WebClient

$webText = $wc.DownloadString($url)
$w = $webtext.Split("`n")

$d = $w[4]
$d = $d.Split("AS-IS")
#$d = $d.split("""")
$d = $d[5]
$d = $d.Substring(2)
$d = $d.Trim()
$b = "Date: $d Searching for $s from website $url`n`n"
$bodyLen = $b.Length
if (test-path -Path $datefile) {
	$dd = Get-Content $datefile
}

if ($d -eq $dd) {
	exit
}


if (test-path -Path $datefile) {
Remove-Item $datefile
}

$d | Out-File -Encoding ASCII -append -NoClobber $datefile

$w | ForEach-Object {
	$ww = $_
	$s | ForEach-Object {
		if ($ww -like "*$_*")
			{$b += "$ww`n"}
	}
}

# don't send any email unless something is found.
if ($b.Length -eq $bodylen) {
	exit
}

$body = $b
$smtp.Send($emailFrom,$emailTo, $subject, $body)

